package com.example.service.common.api;

import com.example.service.common.api.entity.ResponseResult;
import com.example.service.common.api.fallback.Service1FallBack;
import com.example.service.common.dto.FileTestDto;
import com.example.service.common.dto.TestDto;
import com.example.service.common.vo.TestVo;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@FeignClient(value = "service1-provider-app",path = "/service1",
        fallback = Service1FallBack.class)
public interface Service1 {

    @PostMapping("/post/pathAndBodyArg/hystrix/{name}")
    ResponseResult<TestVo> pathAndBodyArgPostHystrix(@PathVariable("name")String name, TestDto dto);

    @GetMapping("/get/noArg/hystrix")
    public ResponseResult<TestVo> noArgGetHystrix();

    @GetMapping("/get/noArg")
    ResponseResult<TestVo> noArgGet();

    @GetMapping("/get/pathArg/{name}/{date}")
    ResponseResult<TestVo> pathArgGet(@PathVariable("name")String name,@DateTimeFormat(pattern = "yyyy-MM-dd") @PathVariable("date")LocalDate date);

    @PostMapping(value = "/post/pathAndBodyArg/{name}/{date}",consumes = MediaType.APPLICATION_JSON_VALUE)
    ResponseResult<TestVo> pathAndBodyArgPost(@PathVariable("name")String name,
                                              @DateTimeFormat(pattern = "yyyy-MM-dd") @PathVariable("date")LocalDate date,
                                              @RequestBody TestDto dto);

    @PutMapping("/put/pathAndBodyArg/{name}/{date}")
    TestVo pathAndBodyArgPut(@PathVariable("name")String name, @PathVariable("date")LocalDate date,
                                 @RequestBody TestDto dto);

    @PostMapping("/post/file/{e}")
    ResponseResult<TestVo> pathAndBodyArgAndFileArgPost(@PathVariable("e") String e,
                                                               @RequestBody FileTestDto fileTestDto);
}
